<template>
	<view class="page">
		<view class="flex benben-position-layout flex flex-wrap align-center personalInformation_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub personalInformation_fd0_0'>
				<view class='flex flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
					<text class='fu-iconfont2  personalInformation_fd0_0_c0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">&#xE794;</text>
				</view>
				<text class='personalInformation_fd0_0_c1'>个人资料</text>
				<view class='flex flex-wrap align-center personalInformation_fd0_0_c2'>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<!---flex布局flex布局开始-->
		<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout personalInformation_flex_1">
			<view class='flex flex-wrap align-center justify-between personalInformation_fd1_0'>
				<text class='personalInformation_fd1_0_c0'>头像</text>
				<view class="upload position-relative">

					<image class=" personalInformation_fd1_0_c1_image" mode="aspectFit"
						@tap="croppingUploadImage('head_img_id','head_img',false,user)"
						:src="user.head_img"></image>
				</view>
			</view>
			<view class='flex flex-wrap align-center justify-between personalInformation_fd1_1'>
				<text class='personalInformation_fd1_1_c0'>昵称</text>
				<input class='flex-sub personalInformation_fd1_1_c1' type="text" placeholder="请输入昵称" confirm-type="done"
					:maxlength="14" :disabled='disableds' placeholder-style="color:rgba(102, 102, 102, 1);font-size:32rpx"
					v-model="user.user_nickname" />
			</view>
			<view class='flex flex-wrap align-center justify-between personalInformation_fd1_2'
				@tap.stop="selectSex">
				<text class='personalInformation_fd1_2_c0'>性别</text>
				<input class='flex-sub personalInformation_fd1_2_c1' type="text" placeholder="请选择性别" confirm-type="done"
					:maxlength="-1" :disabled='true' placeholder-style="color:rgba(102, 102, 102, 1);font-size:32rpx"
					v-model="sexLable" />
			</view>
			<view class='flex flex-wrap align-center justify-between personalInformation_fd1_3'>
				<text class='personalInformation_fd1_3_c0'>手机号</text>
				<text class='personalInformation_fd1_3_c1'>{{user.mobile}}</text>
			</view>
			<view class='flex flex-wrap align-center justify-between personalInformation_fd1_1'>
				<text class='personalInformation_fd1_1_c0'>省份</text>
				<input class='flex-sub personalInformation_fd1_1_c1' type="text" placeholder="请输入省份" confirm-type="done" :disabled='disableds'
					:maxlength="14" placeholder-style="color:rgba(102, 102, 102, 1);font-size:32rpx"
					v-model="user.shengfen" />
			</view>
			<view class='flex flex-wrap align-center justify-between personalInformation_fd1_1'>
				<text class='personalInformation_fd1_1_c0'>院校</text>
				<input class='flex-sub personalInformation_fd1_1_c1' type="text" placeholder="请输入院校" confirm-type="done" :disabled='disableds'
					:maxlength="14" placeholder-style="color:rgba(102, 102, 102, 1);font-size:32rpx"
					v-model="user.school_name" />
			</view>
			<view class='flex flex-wrap align-center justify-between personalInformation_fd1_1'>
				<text class='personalInformation_fd1_1_c0'>班级</text>
				<input class='flex-sub personalInformation_fd1_1_c1' type="text" placeholder="请输入班级" confirm-type="done" :disabled='disableds'
					:maxlength="14" placeholder-style="color:rgba(102, 102, 102, 1);font-size:32rpx"
					v-model="user.class_name" />
			</view>
		</view>

		<view class="save_button" @tap="getsubSet">保存</view>

		<!---flex布局flex布局结束-->
		<!--性别选择器开始 -->
		<benben-picker ref="benbenWritePickerCodepicker2" :visible.sync="pickerDiy1658997072074" :label.sync='sexLable'
			:value.sync='user.sex' :options='sexType' mode='selector' :mask-show='true' :timeout='true'
			:picker-height='100' default-type='value' :default-props='{"label":"name","value":"value"}'>
			<template #picker-header>
				<view class='flex flex-wrap align-center justify-between personalInformation_picker2_0'>
					<text class='personalInformation_picker2_0_c0'
						@tap="$refs.benbenWritePickerCodepicker2.cancel()">取消</text>
					<text class='personalInformation_picker2_0_c1'>选择性别</text>
					<text class='personalInformation_picker2_0_c2'
						@tap="$refs.benbenWritePickerCodepicker2.pickerConfirm()">确定</text>
				</view>
			</template>
		</benben-picker>
		<!--性别选择器结束 -->

	</view>
</template>
<script>
	import UploadImage from '@/common/utils/upload-image.js'
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},

		data() {
			return {
				"pickerDiy1658997072074": false,
				"sexType": [{
					"name": "保密",
					"value": "0",
					"image": ""
				},{
					"name": "男",
					"value": "1",
					"image": ""
				}, {
					"name": "女",
					"value": "2",
					"image": ""
				}],
				"sexLable": "保密",
				"sexValue": "0",
				"user": {
					"invite_code": "",
					"address": "",
					"address_code": "",
					"address_citycode": "",
					"id": "",
					"lastid": "",
					"user_nickname": "",
					"mobile": "",
					"user_name": "",
					"head_img": "",
					"birthday": "",
					"is_finger": "",
					"user_money": "",
					"freeze_money": "",
					"withdrawal_money": "",
					"score": "",
					"empirical": "",
					"invoice_title": "",
					"invoice_company_title": "",
					"total_consumption_money": "",
					"sex": "",
					"create_time": "",
					"phone": "",
					"online": "",
					"_mobile": "",
					"coupon": "",
					"age": "",
					"collection_count": "",
					"browse_count": "",
					"certified": "",
					"invite": []
				},
				"head_img_id": "",
				"isClick": false,
				"disableds": false,
			};
		},
		computed: {
			userInfo: {
				get() {
					return this.$store.state.userInfo
				},
				set() {
					this.$store.commit('updateUserInfo', value)
				},
			}
		},
		watch: {},
		onLoad(options) {
			this.getgetUser();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//裁剪图片上传
			croppingUploadImage(id, path, obj, obj1, fnName = false) {
				if (this.user.id == 130) {
					return;
				}
				let self = this
				if (!obj) obj = this
				if (!obj1) obj1 = this
				let itemList = obj1[path] ? ['修改头像', '拍照', '从手机相册选择'] : ['拍照', '从手机相册选择']

				function imageCroppingCuccess() {
					uni.$once('image-cropping-success', (file) => {
						if (!file) return
						new UploadImage([file], {
							complete: (res) => {
								if (id) self.$set(obj, id, res[0].id)
								if (path) self.$set(obj1, path, res[0].path)
								if (fnName) self[fnName]()
							},
						})
					})
				}
				uni.showActionSheet({
					itemList: itemList,
					success: function(res) {
						if (res.tapIndex == 0 && obj1[path]) {
							uni.navigateTo({
								url: '/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType="jpg"&myImgUrl=' +
									obj1[path],
								animationDuration: 0,
							})
							imageCroppingCuccess()
						}
						if ((res.tapIndex == 1 && obj1[path]) || (res.tapIndex == 0 && !obj1[path])) {
							uni.chooseImage({
								count: 1,
								sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
								sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
								success: (res) => {
									// 跳转到图片裁切页面
									uni.navigateTo({
										url: '/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType="jpg"&myImgUrl=' +
											res.tempFilePaths[0],
										animationDuration: 0,
									})
									imageCroppingCuccess()
								},
							})
						}
						if ((res.tapIndex == 2 && obj1[path]) || (res.tapIndex == 1 && !obj1[path])) {
							uni.chooseImage({
								count: 1,
								sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
								sourceType: ['album'], // 可以指定来源是相册还是相机，默认二者都有
								success: (res) => {
									// 跳转到图片裁切页面
									uni.navigateTo({
										url: '/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType="jpg"&myImgUrl=' +
											res.tempFilePaths[0],
										animationDuration: 0,
									})
									imageCroppingCuccess()
								},
							})
						}
					},
					fail: function(res) {
						console.log(res.errMsg)
					},
				})
			},
			//获取个人信息
			async getgetUser() {
				//请求方法
				//数据验证

				let userData = await this.$api.post(global.apiUrls.post5c78c4772da97, {
					user_id: this.userInfo.id
				});
				if (userData.data.code != 1) {
					this.$message.info(userData.data.msg);
					return
				}
				let userinfo = userData.data;
				this.user = userinfo.data;
				if (this.user.sex == 1) {
					this.sexLable = '男';
				} else if (this.user.sex == 2) {
					this.sexLable = '女';
				} else {
					this.sexLable = '保密';
				}
				if (this.user.id == 130) {
					this.disableds = true;
				} else {
					this.disableds = false;
				}
			},
			//提交修改信息
			async getsubSet() {
				if (this.user.id == 130) {
					this.$message.info('请登录正式账号进行修改');
					return;
				}
				if (this.isClick) return;
				if (!validate(this.user.user_nickname, 'require')) {
					this.$message.info('请输入您的昵称');
					return false;
				}
				//请求方法
				//数据验证
				this.isClick = true;
				let setUserData = await this.$api.post(global.apiUrls.post5cb54af125f1c, {
					head_img: this.user.head_img,
					user_nickname: this.user.user_nickname,
					sex: this.user.sex,
					user_id: this.user.id,
					shengfen: this.user.shengfen,
					school_name: this.user.school_name,
					class_name: this.user.class_name
				});
				if (setUserData.data.code != 1) {
					this.isClick = false;
					this.$message.info(setUserData.data.msg);
					return
				}
				let setUserinfo = setUserData.data;
				// this.setUser = setUserinfo.data
				this.$message.info(setUserData.data.msg);
				setTimeout(() => {
					this.isClick = false;
					uni.navigateBack({
						delta: 1
					});
				}, 800)
				
			},
			selectSex() {
				if (this.user.id == 130) {
					return;
				} else {
					this.pickerDiy1658997072074 = true;
				}
			}
		}
	};
</script>
<style lang="scss" scoped>
	.save_button {
		width: 686rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		background: #1593FF;
		color: #ffffff;
		border-radius: 44rpx;
		position: absolute;
		bottom: 48rpx;
		left: 32rpx;
		font-size: 32rpx;
	}

	.personalInformation_picker2_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		background-size: 100% !important;
		padding: 0rpx 32rpx 0rpx 32rpx;
		border-radius: 16rpx 16rpx 0rpx 0rpx;
		background-size: 100% auto !important;
		height: 100rpx;
	}

	.personalInformation_picker2_0_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #BFBFBF;
	}

	.personalInformation_picker2_0_c1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
	}

	.personalInformation_picker2_0_c2 {
		color: rgba(44, 143, 255, 1);
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
	}

	.personalInformation_fd1_0 {
		border-bottom: 1px solid #eee;
		height: 153rpx;
	}

	.personalInformation_fd1_0_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_0_c1_image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50rpx 50rpx 50rpx 50rpx;
	}

	.personalInformation_fd1_1 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_1_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_1_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.personalInformation_fd1_2 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_2_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_2_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.personalInformation_fd1_3 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_3_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_3_c1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #666666;
	}

	.personalInformation_flex_1 {
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.personalInformation_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		height: 88rpx;
	}

	.personalInformation_fd0_0_c0_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
		line-height: 36rpx;
	}

	.personalInformation_fd0_0_c1 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
		line-height: 50rpx;
	}

	.personalInformation_fd0_0_c2 {
		width: 36rpx;
		height: 36rpx;
	}

	.personalInformation_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		background-size: 100% !important;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.page {
		min-height: calc(100vh - var(--window-bottom));
		background: #fff;
		background-size: 100% auto !important;
	}
</style>